home *** CD-ROM | disk | FTP | other *** search
- Subject: Re: Menu Questions
- Sent: 5/15/96 11:35 AM
- Received: 5/17/96 9:02 AM
- From: Mary Boetcher, Mary_Boetcher@quickmail.apple.com
- Reply-To: ODF-Interest@CILabs.ORG
- To: OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
-
- Reply to: RE>Menu Questions
-
- >> Once I have the menu created, I want to use the menu item text to tell me
- >> which font to set when one is chosen from the menu. How can I get the item
- >> text of the selected item in my part's DoMenu method?
- --------
-
- Here is some code from my test part that creates and manages a font menu. You
- should define a range of command numbers to represent the font menu items.
-
- void AddFontsToMenu(Environment* ev, FW_CPullDownMenu* menu)
- {
- short count = 0;
- FW_CFontIterator fontIter;
- FW_CString fontName;
- ODCommandID commandID = cFirstFontCommand;
- for (fontName = fontIter.First(); fontIter.IsNotComplete(); fontName =
- fontIter.Next())
- {
- menu->AppendTextItem(ev, fontName, commandID+count);
- count++;
- }
- gFontCount = count;
- }
-
- FW_Boolean CMyEditView::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus, FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- //-- Enable all items in the Font menu
- ODCommandID c = cFirstFontCommand;
- for (short i=0; i < gFontCount; c++, i++)
- menuBar->EnableAndCheckCommand(ev, c, true, false);
-
- //-- Put a check in front of the current font
- c = GetCurrentFontCmd(ev, menuBar);
- if (c != 0)
- menuBar->CheckCommand(ev, c, true);
- }
-
- return FW_CEditView::DoAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
- }
-
- ODCommandID CMyEditView::GetCurrentFontCmd(Environment* ev, FW_CMenuBar*
- menuBar)
- {
- ODCommandID result = 0;
-
- ODCommandID c = cFirstFontCommand;
- FW_CString fontName;
- for (short i=0; i < gFontCount; i++, c++)
- {
- menuBar->GetItemString(ev, c, fontName);
- if (fontName == fFontName)
- {
- result = c;
- break;
- }
-
- return result;
- }
-
- return result; // could be 0
- }
-
- FW_Boolean CMyEditView::DoMenu(Environment* ev, const FW_CMenuEvent&
- theMenuEvent) // Override
- {
- FW_Boolean menuHandled = true;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- if (cFirstFontCommand <= id && id < cFirstFontCommand+gFontCount)
- {
- this->CommandToString(ev, id, fFontName);
- this->DoSetFont(ev);
- return menuHandled;
- }
- ...
- }
-
- Mary Boetcher
- ODF Person
-